package _021_10_5

import "sort"

type pairSlice []pair

type pair struct {
	num int
}

func (item pairSlice) Swap(i, j int) {
	temp := item[i]
	item[i] = item[j]
	item[j] = temp
}
func (item pairSlice) Len() int {
	return len(item)
}
func (item pairSlice) Less(i, j int) bool {
	return item[i].num < item[j].num
}

func GetLeastNumbers_Solution(input []int, k int) []int {
	var data pairSlice
	for i := 0; i < len(input); i++ {
		data = append(data, pair{
			input[i],
		})
	}
	sort.Sort(data)
	result := make([]int, k-1)
	for i := 0; i < k; i++ {
		result[i] = data[i].num
	}
	return result
}
